package com.thon.entity.project;


import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.thon.commons.config.Global;
import com.thon.commons.utils.ImageUrl;
import com.thon.entity.user.User;
import com.thon.entity.util.IdEntity;

@Entity
@Table(name = "preferential")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Preferential extends IdEntity {

	private static final long serialVersionUID = -7549842588315162385L;
	
	private ProjectCategory projectCategory;	
	private User user;
	private String name;
	private String activityBackground;	
	private String description;
	private Date createdDate;	
	private String tags;
	private Integer status;
	private Integer photoId;
	private Integer commentCount;
	private Integer  shareCount;
	

	




	//优惠活动的状态，0-预审的项目，1-开启的优惠活动，2-关闭的优惠活动
	public static final Integer preferential_STATUS_CLOSE = 2;
	public static final Integer preferential_STATUS_OPEN = 1;
	public static final Integer preferential_STATUS_PRE = 0;
	
	public Preferential() {
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	

	

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "category_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public ProjectCategory getProjectCategory() {
		return this.projectCategory;
	}

	public void setProjectCategory(ProjectCategory projectCategory) {
		this.projectCategory = projectCategory;
	}
	
	

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getActivityBackground() {

		if(!StringUtils.isBlank(activityBackground)){
			activityBackground = StringEscapeUtils.unescapeHtml4(activityBackground);
			activityBackground = activityBackground.replaceAll("src=\"../common/attachment/download/", "src=\""+Global.getConfig("img.url"));
		}
		return activityBackground;
	}

	public void setActivityBackground(String activityBackground) {
		this.activityBackground = activityBackground;
	}

	

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	

	public String getTags() {
		return this.tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	
	public Integer getPhotoId() {
		return this.photoId;
	}

	public void setPhotoId(Integer photoId) {
		this.photoId = photoId;
	}
	

	@Transient
	public String getPhotoUrl() {
		return ImageUrl.format(this.photoId);
	}
	
	public Integer getCommentCount() {
		return this.commentCount;
	}

	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}
	
	public Integer getShareCount() {
		return this.shareCount;
	}

	public void setShareCount(Integer shareCount) {
		this.shareCount = shareCount;
	}
}
